import Nerv from "nervjs";
import Taro from "@tarojs/taro-h5";
import { View } from '@tarojs/components';
import { AtActivityIndicator } from 'taro-ui';
import Actions from '../../utils/actions';
import Api from '../../utils/api';
import Utils from '../../utils/utils';
import './login.scss';
export default class IndexPage extends Taro.Component {
  constructor() {
    super(...arguments);

    this.state = {
      loading: true
    };
  }
  //////////////////////////////////// Hooks ////////////////////////////////
  async componentWillMount() {
    Utils.debug('login/login');
    //登录
    try {
      const code = '';
      const res = await Api.request(Actions.LOGIN, { code: code });
      const data = res.data;
      const token = data.list[0].token;
      Api.setToken(token);
      //跳转到主页
      Taro.redirectTo({
        url: '../index'
      });
    } catch (e) {
      Utils.error(e);
    }
  }
  //////////////////////////////////// Hooks ///////////////////////////////
  render() {
    const { loading } = this.state;
    return <View style="position: relative;padding:100px;">
        {loading && <AtActivityIndicator content="正在登录..." mode="center"></AtActivityIndicator>}
      </View>;
  }
  config = {
    navigationBarTitleText: '系统登录'
  };

  componentDidMount() {
    super.componentDidMount && super.componentDidMount();
  }

  componentDidShow() {
    super.componentDidShow && super.componentDidShow();
  }

  componentDidHide() {
    super.componentDidHide && super.componentDidHide();
  }

}